package com.ruoyi.wwxkf.service.impl;

import com.ruoyi.utils.wwx.WwxNetWorkUtil;
import com.ruoyi.utils.contast.WxxContast;
import com.ruoyi.wwxkf.service.WwxKfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

@Service
public class WwxKfServiceImpl implements WwxKfService {
    @Autowired
    public RedisTemplate redisTemplate;
    @Override
    public String getAccessToken() {
        Object o =  redisTemplate.opsForValue().get(WxxContast.GET_MESSAGE_TOKEN_KEY);
        if (Objects.isNull(o)){
            String accessToken = WwxNetWorkUtil.getAccessToken();
            redisTemplate.opsForValue().set(WxxContast.GET_MESSAGE_TOKEN_KEY,accessToken,100, TimeUnit.MINUTES);
            return accessToken;
        }else {
            return o.toString();
        }
    }
}
